<?php
use yii\helpers\ArrayHelper;

?>
<form class="layui-form" action="/article-class/edit">
    <div class="layui-form-item">
        <label class="layui-form-label">文章分类名</label>
        <div class="layui-input-inline">
            <input type="text" name="article_class_name"
                   value="<?= ArrayHelper::getValue($info, 'article_class_name') ?>"
                   lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="text" name="sort" value="<?= ArrayHelper::getValue($info, 'sort') ?>" lay-verify="required|number"
                       class="layui-input"
                       placeholder="默认50，越大越靠前">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否显示</label>
        <div class="layui-input-block">
            <input type="checkbox" checked="" value="1" name="is_show" lay-skin="switch"
                   lay-text="ON|OFF">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="<?= Yii::$app->request->csrfParam ?>"
                   value="<?= Yii::$app->request->csrfToken ?>">
            <input type="hidden" name="article_class_id" value="<?= ArrayHelper::getValue($info, 'article_class_id') ?>">
            <input type="button" class="layui-btn editForm" value="保存">
        </div>
    </div>
</form>
<script>
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer,
            form = layui.form();
        $('.editForm').click(function () {
            var formObj = $(this).closest('form');
            var url = formObj.attr('action');
            var data = formObj.serializeArray();
            var jsonObj = {};
            for (var i in data) {
                jsonObj[data[i].name] = data[i].value;
            }
            $.post(url, jsonObj, function (rs) {
                if (rs.code === 0) {
                    layer.msg(rs.msg);
                    setTimeout(function () {
                        window.location.href = rs.redirect;
                    }, 1000);
                } else {
                    layer.msg(rs.msg);
                }
            });
            return false;
        });
    });
</script>